<?php
/**
 * 门票订单
 *
 * @copyright  Copyright (c) 2015-2025 NcPHP Inc. (http://www.ncphp.com)
 * @license    http://www.ncphp.com
 * @link       http://www.ncphp.com
 * @author	   NcPHP Team
 * @since      File available since Release v1.1
 */
defined('InNcPHP') or exit('Access Invalid!');

class orderModel extends Model{

    public $status = array('10'=>'待支付', '20'=>'待使用', '21'=>'已完成', '30'=>'已取消','31'=>'退款中','32'=>'已退款');
    public $type   = array('1'=>'酒店','2'=>'门票','3'=>'美食','4'=>'旅行社');
    public $pay_type = array('1'=>'微信支付','2'=>'支付宝','3'=>'手动确认收款');
	public function __construct(){
		parent::__construct('order');
	}

    /**
     * 获取列表分页
     * @param array $condition
     * @param string $field
     * @param int $page
     * @param string $order
     * @return mixed
     */
    public function getOrderListPage($condition = array(), $field = '*', $page = 0, $order = 'order_id desc'){
        return $this->field($field)->where($condition)->page($page)->order($order)->select();
    }

    /**
     * 获取一条记录的详细信息
     * @param array $condition
     * @param string $field
     * @return mixed
     */
	public function getOrderInfo($condition = array(), $field = '*',$order = "order_id desc"){
        return $this->field($field)->where($condition)->order($order)->find();
    }

    /**
     * 插入一条记录
     * @param array $params
     * @return mixed
     */
    public function addOrder($params)
    {
        return $this->insert($params);
    }

    /**
     * 更新记录
     * @param array $condition
     * @param array $params
     * @return mixed
     */
    public function updateOrder($condition, $params)
    {
        return $this->where($condition)->update($params);
    }

    /**
     * 获取记录数组
     * @param array $condition
     * @param string $field
     * @param string $order
     * @return mixed
     */
    public function getOrderList($condition = array(), $field = '*', $order = 'order_id desc'){
	    return $this->field($field)->where($condition)->order($order)->select();
    }

    /**
     * 取得订单数量
     * @param array $condition
     */
    public function getOrderCount($condition) {
        return $this->table('order')->where($condition)->count();
    }


    public function get_order_status_count($condition){
        $field = "count(order_status=10 or null ) as 'pay_count', ".
            " count(if(if_examine='0' and order_status=20,true,null)) AS un_shoping_count , ".
//            " count(if(if_examine=2 and order_status=20,true,null)) AS refuse_shoping_count , ".
            " count(order_status=20 or null ) as 'shoping_count', ".
            " count(order_status=21 or null ) as 'complete_count', ".
            " count(order_status=31 or null ) as 'refund_count' ";
        return $this->field($field)->where($condition)->find();
    }

}
?>